﻿using scripts.net;
using System;

namespace scripts.logic
{
	public partial class EventHandler
	{
		public static void OnDisconnect(ClientState state)
		{

		}

		public static void OnTimer()
		{
			CheckPing();
		}

		public static void CheckPing()
		{
			//现在时间戳
			long timeNow = NetManager.GetTimeStamp();
			//开始心跳机制筛查
			foreach(ClientState state in NetManager.clients.Values)
			{
				if(timeNow - state.lastPingTime > NetManager.pingInterval * 4)
				{
					Console.WriteLine("Ping Close " + state.socket.RemoteEndPoint.ToString());
					NetManager.Close(state);
					//每一次最多断开一个客户端连接 foreach遍历中删除是危险操作
					return;
				}
			}
		}
	}
}
